"""
    地址：https://leetcode.cn/problems/two-sum/
题目：
    给定一个整数数组 nums 和一个整数目标值 target，
    请你在该数组中找出 和为目标值 target  的那 两个 整数，
    并返回它们的数组下标。

示例 1：

输入：nums = [2,7,11,15], target = 9
输出：[0,1]
解释：因为 nums[0] + nums[1] == 9 ，返回 [0, 1] 。
"""

class Solution:
    def __init__(self):
        print("对象创建了")

    def towSum_v1(self, nums: list[int], target: int) -> list[int]:
        result = []
        for i in range(len(nums) - 1):
            for j in range(i+1,len(nums)):
                if(nums[i] + nums[j] == target):
                  result.append(i)
                  result.append(j)
                  return result


    def towSum_v2(self,nums: list[int],target: int) -> list[int]:
        result = []
        map = {}
        for index,value in enumerate(nums):
            map[value] = index
        print(map)

        less = 0
        for i in range(len(nums)):
            less = target - nums[i]
            print(f"less is {less}, i is :{i}")
            if(map.get(less) != None) and map[less] != i:
                result.append(i)
                result.append(map[less])
                return result
        return result

nums = [2,7,11,15]
solution = Solution()
print(solution.towSum_v2(nums,9))

nums = [2,5,5,11]
print(solution.towSum_v2(nums,10))